package com.art.museumbackend.controller;

import com.art.museumbackend.entity.Articles;
import com.art.museumbackend.entity.Columns;
import com.art.museumbackend.entity.PageBean;
import com.art.museumbackend.entity.Result;
import com.art.museumbackend.service.ArticlesService;
import com.art.museumbackend.service.ColumnService;
import com.art.museumbackend.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
@Validated
public class showController {

    @Autowired
    private ColumnService columnService;

    @Autowired
    private ArticlesService articlesService;

//    获取父栏目（直接select所有）
    @GetMapping("/getPColumns")
    public Result<List<Columns>> getParentColumns() {
        List<Columns> columns=columnService.getParentColumns();
        return ResultUtil.success(columns);
    }
//  根据父栏目获取子栏目
    @GetMapping("/getColumns")
    public Result<List<Columns>> getChildrenColumns(@RequestParam("pid") Integer pid) {
        List<Columns> columns=columnService.getChildrenColumns(pid);
        return ResultUtil.success(columns);
    }

//获得栏目对应的文章
    @GetMapping("/ArticleList")
    public Result<List<Articles>> list(
            @RequestParam(required = false) Integer parentColumnId,
            @RequestParam(required = false) Integer subColumnId
    ) {
        List<Articles> articleList =  articlesService.articleListById(parentColumnId,subColumnId);
        return ResultUtil.success(articleList);
    }

//  获得栏目详情
    @GetMapping("/columnDetail")
    public Result<Columns> getColumnById(@RequestParam("cid") Integer cid) {
        Columns columns = columnService.getColumnById(cid);
        return ResultUtil.success(columns);
    }



//获取文章详情
    @GetMapping("/ArticleDetail")
    public Result<Articles> getArticleDetail(@RequestParam("articleId") Integer articleId) {
        Articles article = articlesService.getArticleById(articleId);
        return ResultUtil.success(article);
    }
}
